// 在React.StrictMode模式下，初始会触发两次，造成JiessDialog每次打开执行两次
import Dialog from './Dialog.js';
// 全局弹框可以注入上下文
let instance = null;
// 调用上下文中的this.dialog方法获取弹框实例
export const dialogInstance = (fn, ...args) => {
	if (typeof fn === 'function') {
		instance.open(fn, ...args);
	} else {
		return instance;
	}
};
export default function(hook, { is }) {
	const { $m, hookDialog } = hook;
	return {
		isJiess: true,
		name: 'JiessDialog',
		// 初始注册提供的参数
		setup(props) {
			const initNode = (show, param, ...children) => {
				if (typeof param === 'function') param = param.call(this, show);
				const dd = hookDialog.call(this, show);
				return { is, children, ...dd, ...props, ...param };
			};
			const { childs } = instance = new Dialog(this, hook, initNode);
			this.add({ children: { $proxy: childs } });
		}
	}
}